import {type baseResponse, useAxios} from "@/api/index";

export interface siteInfoType {
    "site": {
        "title": string
        "enTitle": string
        "logo": string
        "slogan": string
        "abstract": string
        "beian": string
    },
    "project": {
        "title": string
        "icon": string
        "webPath": string
    },
    "seo": {
        "keywords": string
        "description": string
    },
    "register": {
        "isEmailRegister": boolean
        "isWxRegister": boolean
        "isSmsRegister": boolean
    },
    "login": {
        "isUsernameLogin": boolean
        "isEmailLogin": boolean
        "isTelLogin": boolean
        "userSimultaneousLoginCount": number
    }
}

export function getSiteInfoApi(): Promise<baseResponse<siteInfoType>> {
    return useAxios.get("/api/settings/site_info")
}

export function updateSiteInfoApi(data: siteInfoType): Promise<baseResponse<string>> {
    return useAxios.put("/api/settings/site_info", data)
}


export interface aiType {
    model: string,
    proxyUrl: string,
    apiKey: string,
    createRoleScope: number,
    updateRoleScope: number,
    deleteRoleScope: number,
    recommendRoleScope: number,
    registerUserScope: number,
    chatScope: number,
    prompt: string
}

export interface wxLoginType {
    appId: string,
    secret: string,
    wxToken: string
}

export interface aliPayType {
    kAppId: string,
    kPrivateKey: string,
    kServerDomain: string
    subject:string
    orderExpire: number
}

export interface emailType {
    domain: string,
    port: number,
    email: string,
    authorizationCode: string,
    sendingName: string,
    ssl: boolean
    tls: boolean
    registerTemplate: string,
    bindTemplate: string
}

export interface smsType {
    username: string,
    password: string,
    codeToken: string,
    registerTemplateId: string,
    bindTemplateId: string,
    noticeToken: string
}

export interface ocrType {
    url: string
    compress: number
}

export interface siteType {
    site_info: siteInfoType
    ai: aiType
    wx_login: wxLoginType
    ali_pay: aliPayType
    email: emailType
    sms: smsType
    ocr: ocrType
}

//构造一个泛型接受name，自动转成对应的对象
export function getSiteConfigApi<T extends keyof siteType>(name: T): Promise<baseResponse<siteType[T]>> {
    return useAxios.get("/api/settings/" + name)
}


export function updateSiteConfigApi<T extends keyof siteType>(name: T, data: siteType[T]): Promise<baseResponse<string>> {
    return useAxios.put("/api/settings/" + name, data)
}